home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / nrdump.c < prev    next >
C/C++ Source or Header  |  1993-04-30  |  3KB  |  125 lines

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netrom.h"
  8. #include "nr4.h"
  9. #include "trace.h"
  10.  
  11. /* Display NET/ROM network and transport headers */
  12. void
  13. netrom_dump(fp,bpp,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     char src[AXALEN],dest[AXALEN];
  19.     char tmp[AXBUF];
  20.     char thdr[NR4MINHDR];
  21.     register i;
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.     /* See if it is a routing broadcast */
  26.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  27.         (void)PULLCHAR(bpp);        /* Signature */
  28.         pullup(bpp,tmp,ALEN);
  29.         tmp[ALEN] = '\0';
  30.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  31.         for(i = 0;i < NRDESTPERPACK;i++) {
  32.             if (pullup(bpp,src,AXALEN) < AXALEN)
  33.                 break;
  34.             fprintf(fp,"        %12s",pax25(tmp,src));
  35.             pullup(bpp,tmp,ALEN);
  36.             tmp[ALEN] = '\0';
  37.             fprintf(fp,"%8s",tmp);
  38.             pullup(bpp,src,AXALEN);
  39.             fprintf(fp,"    %12s",pax25(tmp,src));
  40.             tmp[0] = PULLCHAR(bpp);
  41.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  42.         }
  43.         return;
  44.     }
  45.     /* See if it is a routing poll - WG7J */
  46.     if(uchar(*(*bpp)->data) == NR3POLLSIG) {
  47.         (void)PULLCHAR(bpp);        /* Signature */
  48.         pullup(bpp,tmp,ALEN);
  49.         tmp[ALEN] = '\0';
  50.         fprintf(fp,"NET/ROM Poll: %s\n",tmp);
  51.         return;
  52.     }
  53.     /* Decode network layer */
  54.     pullup(bpp,src,AXALEN);
  55.     fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  56.  
  57.     pullup(bpp,dest,AXALEN);
  58.     fprintf(fp,"->%s",pax25(tmp,dest));
  59.  
  60.     i = PULLCHAR(bpp);
  61.     fprintf(fp," ttl %d\n",i);
  62.  
  63.     /* Read first five bytes of "transport" header */
  64.     pullup(bpp,thdr,NR4MINHDR);
  65.     switch(thdr[4] & NR4OPCODE){
  66.      case NR4OPPID:    /* network PID extension */
  67.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  68.              ip_dump(fp,bpp,check) ;
  69.             return;
  70.         }
  71.          else
  72.              fprintf(fp,"         protocol family %x, proto %x",
  73.              uchar(thdr[0]), uchar(thdr[1])) ;
  74.          break ;
  75.     case NR4OPCONRQ:    /* Connect request */
  76.         fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  77.         i = PULLCHAR(bpp);
  78.         fprintf(fp," wnd %d",i);
  79.         pullup(bpp,src,AXALEN);
  80.         fprintf(fp," %s",pax25(tmp,src));
  81.         pullup(bpp,dest,AXALEN);
  82.         fprintf(fp,"@%s",pax25(tmp,dest));
  83.         break;
  84.     case NR4OPCONAK:    /* Connect acknowledgement */
  85.         fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  86.          uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  87.          uchar(thdr[3]));
  88.         i = PULLCHAR(bpp);
  89.         fprintf(fp," wnd %d",i);
  90.         break;
  91.     case NR4OPDISRQ:    /* Disconnect request */
  92.         fprintf(fp,"         disc: ckt %d/%d",
  93.          uchar(thdr[0]),uchar(thdr[1]));
  94.         break;
  95.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  96.         fprintf(fp,"         disc ack: ckt %d/%d",
  97.          uchar(thdr[0]),uchar(thdr[1]));
  98.         break;
  99.     case NR4OPINFO:    /* Information (data) */
  100.         fprintf(fp,"         info: ckt %d/%d",
  101.          uchar(thdr[0]),uchar(thdr[1]));
  102.         fprintf(fp," txseq %d rxseq %d",
  103.          uchar(thdr[2]), uchar(thdr[3]));
  104.         break;
  105.     case NR4OPACK:    /* Information acknowledgement */
  106.         fprintf(fp,"         info ack: ckt %d/%d",
  107.          uchar(thdr[0]),uchar(thdr[1]));
  108.         fprintf(fp," txseq %d rxseq %d",
  109.          uchar(thdr[2]), uchar(thdr[3]));
  110.         break;
  111.     default:
  112.          fprintf(fp,"         unknown transport type %d",
  113.          thdr[4] & 0x0f) ;
  114.         break;
  115.     }
  116.     if(thdr[4] & NR4CHOKE)
  117.         fprintf(fp," CHOKE");
  118.     if(thdr[4] & NR4NAK)
  119.         fprintf(fp," NAK");
  120.     if(thdr[4] & NR4MORE)
  121.         fprintf(fp," MORE");
  122.     putc('\n',fp);
  123. }
  124.  
  125.